package com.cme.commons.fileupload;

import java.io.IOException;

import alluxio.AlluxioURI;
import alluxio.client.file.FileInStream;
import alluxio.client.file.FileSystem;
import alluxio.exception.AlluxioException;

public class AlluxioReadFile001 {
	public static void main(String[] args) {

		// 1.获取文件系统FileSystem
		FileSystem fs = FileSystem.Factory.get();
		// 2.创建文件路径 AlluxioURI
		AlluxioURI path = new AlluxioURI("/files/writetest001.txt");
		FileInStream in = null;
		try {
			// 3.打开文件输入流
			in = fs.openFile(path);

			// 4.读取文件内容
			byte[] buffer = new byte[1024];
			for (int len = 0; (len = in.read(buffer)) != -1;) {
				String content = new String(buffer, 0, len);
				System.out.println(content);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} catch (AlluxioException e) {
			e.printStackTrace();
		} finally {
			try {
				// 5.关闭输入流，释放资源
				in.close();
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
	}
}
